package com.alan.camunda.boot.delegate;

import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;

/**
 * WaitFor （Timer） 节点前计算等待表达式
 */
@Slf4j
@Component("prepareWaitForDelegate")
public class PrepareWaitForDelegate implements JavaDelegate {


    private final RuntimeService runtimeService;

    public PrepareWaitForDelegate(RuntimeService runtimeService) {
        this.runtimeService = runtimeService;
    }

    @Override
    public void execute(DelegateExecution execution) throws Exception {
        log.info("PrepareWaitForDelegate#execute");
        int seconds = 10;
        execution.setVariableLocal("waitExpression",  "PT"+ seconds +"S");
    }

    public String get(String content) {
        return "PT"+ content +"S";
    }

    public String get(DelegateExecution execution) {
        String nodeId = execution.getCurrentActivityId();
        return "PT"+ 10 +"S";
    }

}
